package com.venue.hjt.venueclass.model;



import android.content.Context;
import android.util.Log;


import com.venue.hjt.venueclass.BaseApplication;
import com.venue.hjt.venueclass.db.CardDao;
import com.venue.hjt.venueclass.db.DynamicSchool;
import com.venue.hjt.venueclass.db.SchAlbum;
import com.venue.hjt.venueclass.db.VenueHour;
import com.venue.hjt.venueclass.db.VenueInfo;
import com.venue.hjt.venueclass.utlis.APPUtlis;
import com.venue.hjt.venueclass.utlis.ClassCalendar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xqx on 2018/1/10.
 *首页model
 */

public class HomeModel {
    public List<String> getAlbum(){
        BaseApplication.getDaoInstant().clear();
        List<String> list=new ArrayList<>();
        list.clear();
        List<SchAlbum> classAlba = CardDao.queryAlbumType("1");
       for (SchAlbum alba:classAlba){
           list.add(alba.getPic());
       }
        return list;
    }
    public String className(){
        List<VenueInfo> cardTeachers = CardDao.queryVenueInfo();
        if (cardTeachers.size()!=0) {
            return cardTeachers.get(0).getVenue_name();
        }
        return "暂无";
    }
    public String getNum(){
        List<VenueInfo> cardTeachers = CardDao.queryVenueInfo();
        if (cardTeachers.size()!=0) {
            return "可容纳 "+cardTeachers.get(0).min_num+"～"+cardTeachers.get(0).max_num+" 人";
        }
        return "暂无";
    }
    public String getDynamic(){
        List<VenueInfo> cardTeachers = CardDao.queryVenueInfo();
        if (cardTeachers.size()!=0) {
            return cardTeachers.get(0).getDescription();
        }
        return "暂无";
    }
    public VenueHour getTime(){
        BaseApplication.getDaoInstant().clear();
        List<VenueHour> venueHours = CardDao.queryHourS("1",ClassCalendar.getWeekDays()+"");
        String strhour = ClassCalendar.getHour();
        double hour1 = Double.parseDouble(strhour);
        for(VenueHour hour:venueHours){
//            Log.e("ATG",hour.getStart_time()+"    "+hour.getEnd_time());
            String start_time = hour.getStart_time();
            String start_time1 = start_time.substring(0, 2);
            String start_time2 = start_time.substring(3,4);
            String start_time3 = start_time.substring(4);
//            if (start_time3.equals("0")){
//                start_time3="01";
//            }
            String end_time = hour.getEnd_time();
            String end_time1 = end_time.substring(0, 2);
            String end_time2 = end_time.substring(3,4);
            String end_time3 = end_time.substring(4);
//            if (end_time3.equals("0")){
//                end_time3="01";
//            }
            String s = start_time1 + "." + start_time2+start_time3;
            String s1 = end_time1 + "." + end_time2+end_time3;
            double v = Double.parseDouble(s);
            double v1 = Double.parseDouble(s1);

            if (v<=hour1&&hour1<=v1){
                Log.e("ATG",hour1+" shijian"+"  "+" "+v+"  "+v1);
                return hour;
            }
        }
        for(VenueHour hour:venueHours){
            String start_time = hour.getStart_time();
            String start_time1 = start_time.substring(0, 2);
            String start_time2 = start_time.substring(3,4);
            String start_time3 = start_time.substring(4);
            if (start_time3.equals("0")){
                start_time3="1";
            }
            String s = start_time1 + "." + start_time2+start_time3;
            double v = Double.parseDouble(s);
            if(hour1<v){
                Log.e("ATG",hour.getStart_time()+" shijia1233n");
                return hour;
            }
        }
//        String id, String weekday, String start_time, String end_time,
//                String status
        return new VenueHour("0","0","0","0","0");
    }
    public float getScore(){
        List<VenueInfo> cardTeachers = CardDao.queryVenueInfo();
        if (cardTeachers.size()!=0) {
            return Integer.parseInt(cardTeachers.get(0).getUser_score());
        }
        return 0;
    }
    public String getComplaint(){
        List<VenueInfo> cardTeachers = CardDao.queryVenueInfo();
        if (cardTeachers.size()!=0) {
            return cardTeachers.get(0).getRegulation();
        }
        return "暂无";
    }
    //校园动态
    public List<String> ArtSchools(){
        BaseApplication.getDaoInstant().clear();
        List<String> strclass=new ArrayList<>();
        List<DynamicSchool> dynamics = CardDao.queryDynamicSchool();
        if (dynamics.size()!=0) {
            for (DynamicSchool dynamic : dynamics) {
                String str=dynamic.getContent().trim().replace("\n","");
                strclass = APPUtlis.handleText(str,31,31.5f);
            }
        }else{
            strclass.add("");
        }
        return strclass;
    }




}
